A robot is located at the top-left corner of a_m_x_n_grid (marked 'Start' in the diagram below).
The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).
How many possible unique paths are there?
Above is a 7 x 3 grid. How many possible unique paths are there?
Note:_m_and_n_will be at most 100.
class Solution {
public:
int uniquePaths\(int m, int n\) {
if \(\(m==1\)\|\|\(n==1\)\){
return 1;
}
int result\[m+1\]\[n+1\];
for \(int i=1;i<=n;i++\){
result\[1\]\[i\]=1;
}
for \(int i=1;i<=m;i++\){
result\[i\]\[1\]=1;
}
for \(int i=2;i<=m;i++\){
for \(int j=2;j<=n;j++\){
result\[i\]\[j\]=result\[i\]\[j-1\]+result\[i-1\]\[j\];
}
}
return result\[m\]\[n\];
}
};